﻿
// MFCAppView.cpp: CMFCAppView 类的实现
//

#include "pch.h"
#include "framework.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义，并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "MFCApp.h"
#endif

#include "MFCAppDoc.h"
#include "MFCAppView.h"
#include "MainFrm.h"
#include "CDialogMosaic.h"
#include "CQuantizationDialog.h"
#include "CDialogHue.h"
#include "CDialogText.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CMFCAppView

IMPLEMENT_DYNCREATE(CMFCAppView, CScrollView)

BEGIN_MESSAGE_MAP(CMFCAppView, CScrollView)
	// 标准打印命令
	ON_COMMAND(ID_FILE_PRINT, &CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CMFCAppView::OnFilePrintPreview)
	ON_WM_CONTEXTMENU()
	ON_WM_RBUTTONUP()
	ON_COMMAND(ID_DIGITIZATION_MOSAIC, &CMFCAppView::OnDigitizationMosaic)
	ON_COMMAND(ID_DIGITIZATION_QUANTIZATION, &CMFCAppView::OnDigitizationQuantization)
	ON_COMMAND(ID_RGB_R, &CMFCAppView::OnRgbR)
	ON_COMMAND(ID_RGB_G, &CMFCAppView::OnRgbG)
	ON_COMMAND(ID_RGB_B, &CMFCAppView::OnRgbB)
	ON_COMMAND(ID_RGBSWAP_RBG, &CMFCAppView::OnRgbswapRbg)
	ON_COMMAND(ID_RGBSWAP_BGR, &CMFCAppView::OnRgbswapBgr)
	ON_COMMAND(ID_RGBSWAP_BRG, &CMFCAppView::OnRgbswapBrg)
	ON_COMMAND(ID_RGBSWAP_GRB, &CMFCAppView::OnRgbswapGrb)
	ON_COMMAND(ID_RGBSWAP_GBR, &CMFCAppView::OnRgbswapGbr)
	ON_COMMAND(ID_CMYK_C, &CMFCAppView::OnCmykC)
	ON_COMMAND(ID_CMYK_M, &CMFCAppView::OnCmykM)
	ON_COMMAND(ID_CMYK_Y, &CMFCAppView::OnCmykY)
	ON_COMMAND(ID_YIQ_Y, &CMFCAppView::OnYiqY)
	ON_COMMAND(ID_YIQ_I, &CMFCAppView::OnYiqI)
	ON_COMMAND(ID_YIQ_Q, &CMFCAppView::OnYiqQ)
	ON_COMMAND(ID_COLOR_HSV, &CMFCAppView::OnColorHsv)
	ON_COMMAND(ID_GRAY_R, &CMFCAppView::OnGrayR)
	ON_COMMAND(ID_GRAY_G, &CMFCAppView::OnGrayG)
	ON_COMMAND(ID_GRAY_B, &CMFCAppView::OnGrayB)
	ON_COMMAND(ID_GRAY_RG, &CMFCAppView::OnGrayMin)
	ON_COMMAND(ID_GRAY_GB, &CMFCAppView::OnGrayMax)
	ON_COMMAND(ID_GRAY_MIDDLE, &CMFCAppView::OnGrayMiddle)
	ON_COMMAND(ID_GRAY_RG32812, &CMFCAppView::OnGrayRg)
	ON_COMMAND(ID_GRAY_GB32813, &CMFCAppView::OnGrayGb)
	ON_COMMAND(ID_GRAY_BR, &CMFCAppView::OnGrayBr)
	ON_COMMAND(ID_GRAY_K, &CMFCAppView::OnGrayK)
	ON_COMMAND(ID_GRAY_Y, &CMFCAppView::OnGrayY)
	ON_COMMAND(ID_GRAY_I, &CMFCAppView::OnGrayI)
	ON_COMMAND(ID_GRAY_L, &CMFCAppView::OnGrayL)
	ON_COMMAND(ID_GRAY_V, &CMFCAppView::OnGrayV)
	ON_COMMAND(ID_ARITHMETIC_ADD, &CMFCAppView::OnArithmeticAdd)
	ON_COMMAND(ID_ARITHMETIC_SUBSTRACT, &CMFCAppView::OnArithmeticSubstract)
	ON_COMMAND(ID_ARITHMETIC_MULTIPLY, &CMFCAppView::OnArithmeticMultiply)
	ON_COMMAND(ID_ARITHMETIC_DIVIDE, &CMFCAppView::OnArithmeticDivide)
	ON_COMMAND(ID_VECTOR_TEXT, &CMFCAppView::OnVectorText)
	ON_COMMAND(ID_ARITHMETIC_LIGHTEN, &CMFCAppView::OnArithmeticLighten)
	ON_COMMAND(ID_ARITHMETIC_DARKEN, &CMFCAppView::OnArithmeticDarken)
	ON_COMMAND(ID_ARITHMETIC_HIGHLIGHT, &CMFCAppView::OnArithmeticLinerlight)
	ON_COMMAND(ID_ARITHMETIC_SCREEN, &CMFCAppView::OnArithmeticScreen)
	ON_COMMAND(ID_GEOMETRIC_TRANSLATE, &CMFCAppView::OnGeometricTranslate)
	ON_COMMAND(ID_GEOMETRIC_SHEARHORIZONTAL, &CMFCAppView::OnGeometricShearhorizontal)
	ON_COMMAND(ID_GEOMETRIC_SHEARVERTICAL, &CMFCAppView::OnGeometricShearvertical)
	ON_COMMAND(ID_GEOMETRIC_SCALE, &CMFCAppView::OnGeometricScale)
	ON_COMMAND(ID_GEOMETRIC_SCALEHORIZONTAL, &CMFCAppView::OnGeometricScalehorizontal)
	ON_COMMAND(ID_GEOMETRIC_SCALEVERTICAL, &CMFCAppView::OnGeometricScalevertical)
	ON_COMMAND(ID_ROTATE_CLOCKWISE90, &CMFCAppView::OnRotateClockwise90)
	ON_COMMAND(ID_ROTATE_CLOCKWISE180, &CMFCAppView::OnRotateClockwise180)
	ON_COMMAND(ID_ROTATE_CLOCKWISE270, &CMFCAppView::OnRotateClockwise270)
	ON_COMMAND(ID_ROTATE_ARBITRARY, &CMFCAppView::OnRotateArbitrary)
	ON_COMMAND(ID_MIRROR_HORIZONTAL, &CMFCAppView::OnMirrorHorizontal)
	ON_COMMAND(ID_MIRROR_VERTICAL, &CMFCAppView::OnMirrorVertical)
	ON_COMMAND(ID_MIRROR_BOTH, &CMFCAppView::OnMirrorBoth)
	ON_COMMAND(ID_GEOMETRIC_SPHERICAL, &CMFCAppView::OnGeometricSpherical)
	ON_COMMAND(ID_GEOMETRIC_RIPPLE, &CMFCAppView::OnGeometricRipple)
	ON_COMMAND(ID_GEOMETRIC_TWIRL, &CMFCAppView::OnGeometricTwirl)
END_MESSAGE_MAP()

// CMFCAppView 构造/析构

CMFCAppView::CMFCAppView() noexcept
{
	// TODO: 在此处添加构造代码

}

CMFCAppView::~CMFCAppView()
{
}

BOOL CMFCAppView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: 在此处通过修改
	//  CREATESTRUCT cs 来修改窗口类或样式

	return CScrollView::PreCreateWindow(cs);
}

// CMFCAppView 绘图

void CMFCAppView::OnDraw(CDC* pDC)
{
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// TODO: 在此处为本机数据添加绘制代码
	if (!pDoc->m_ImageOpen.IsNull())
	{
		pDoc->m_ImageOpen.StretchBlt(
			pDC->m_hDC,
			0, 0,
			pDoc->m_ImageOpen.GetWidth(),
			pDoc->m_ImageOpen.GetHeight(),
			SRCCOPY
		);
	}
}

void CMFCAppView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	CSize sizeTotal;
	// TODO: 计算此视图的合计大小
	sizeTotal.cx = sizeTotal.cy = 100;
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// TODO: add draw code for native data here
	if (!pDoc->m_ImageOpen.IsNull())
	{
		sizeTotal.cx = pDoc->m_ImageOpen.GetWidth();
		sizeTotal.cy = pDoc->m_ImageOpen.GetHeight();
	}
	SetScrollSizes(MM_TEXT, sizeTotal);
}


// CMFCAppView 打印


void CMFCAppView::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
	AFXPrintPreview(this);
#endif
}

BOOL CMFCAppView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// 默认准备
	return DoPreparePrinting(pInfo);
}

void CMFCAppView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 添加额外的打印前进行的初始化过程
}

void CMFCAppView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 添加打印后进行的清理过程
}

void CMFCAppView::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
	ClientToScreen(&point);
	OnContextMenu(this, point);
}

void CMFCAppView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
	theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}


// CMFCAppView 诊断

#ifdef _DEBUG
void CMFCAppView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CMFCAppView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CMFCAppDoc* CMFCAppView::GetDocument() const // 非调试版本是内联的
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCAppDoc)));
	return (CMFCAppDoc*)m_pDocument;
}
#endif //_DEBUG


// CMFCAppView 消息处理程序


void CMFCAppView::OnDigitizationMosaic()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	int nMosaicWidth;
	int nMosaicHeight;

	nMosaicWidth = 3;
	nMosaicHeight = 3;

	CDialogMosaic DialogMosaicOne;
	if (DialogMosaicOne.DoModal() == IDOK)
	{
		nMosaicWidth = DialogMosaicOne.m_nWidth;
		nMosaicHeight = DialogMosaicOne.m_nHeight;
	}
	else {
		return;
	}

	CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();

	pDocNew->m_ImageOpen.Create(pDoc->m_ImageOpen.GetWidth(), pDoc->m_ImageOpen.GetHeight(), 24);

	int nX;  int nY;
	COLORREF PixelColor;
	int nU; int nV;
	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight() - nMosaicHeight; nY = nY + nMosaicHeight)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth() - nMosaicWidth; nX = nX + nMosaicWidth)
		{
			PixelColor = pDoc->m_ImageOpen.GetPixel(nX, nY);
			for (nV = nY; nV <= nY + nMosaicHeight; nV++)
			{
				for (nU = nX; nU <= nX + nMosaicWidth; nU++)
				{
					pDocNew->m_ImageOpen.SetPixel(nU, nV, PixelColor);
				}
			}
		}
	}
	pViewNew->OnInitialUpdate();
}


void CMFCAppView::OnDigitizationQuantization()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	int nLevels;
	nLevels = 2;

	CQuantizationDialog DialogQuantizingOne;

	if (DialogQuantizingOne.DoModal() == IDOK)
	{
		nLevels = DialogQuantizingOne.qLevel;
	}
	else {
		return;
	}

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();

	pDocNew->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	nLevels = nLevels - 1;
	float fRange = nLevels / 255.0;
	float fStep = 255.0 / nLevels;

	int nX; int nY;
	COLORREF PixelColor;
	int nR; int nG; int nB;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			PixelColor = pDoc->m_ImageOpen.GetPixel(nX, nY);
			nR = round(fRange * GetRValue(PixelColor));
			nR = round(fStep * nR);
			nG = round(fRange * GetGValue(PixelColor));
			nG = round(fStep * nG);
			nB = round(fRange * GetBValue(PixelColor));
			nB = round(fStep * nB);
			pDocNew->m_ImageOpen.SetPixel(nX, nY, RGB(nR, nG, nB));
		}
	}
	pViewNew->OnInitialUpdate();

}


void CMFCAppView::OnRgbR()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewRed = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocRed = pViewRed->GetDocument();
	pDocRed->m_ImageOpen.Create(pDoc->m_ImageOpen.GetWidth(), pDoc->m_ImageOpen.GetHeight(), 24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{

			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);

			nR = GetRValue(ColorRefOne);

			pDocRed->m_ImageOpen.SetPixel(nX, nY, RGB(nR, 0, 0));
		}
	}
	pViewRed->OnInitialUpdate();
}


void CMFCAppView::OnRgbG()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewGreen = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocGreen = pViewGreen->GetDocument();
	pDocGreen->m_ImageOpen.Create(pDoc->m_ImageOpen.GetWidth(), pDoc->m_ImageOpen.GetHeight(), 24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nG;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{

			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);

			nG = GetGValue(ColorRefOne);

			pDocGreen->m_ImageOpen.SetPixel(nX, nY, RGB(0, nG, 0));
		}
	}
	pViewGreen->OnInitialUpdate();
}


void CMFCAppView::OnRgbB()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewBlue = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocBlue = pViewBlue->GetDocument();
	pDocBlue->m_ImageOpen.Create(pDoc->m_ImageOpen.GetWidth(), pDoc->m_ImageOpen.GetHeight(), 24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nB;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{

			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);

			nB = GetBValue(ColorRefOne);

			pDocBlue->m_ImageOpen.SetPixel(nX, nY, RGB(0, 0, nB));
		}
	}
	pViewBlue->OnInitialUpdate();
}


void CMFCAppView::OnRgbswapRbg()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewRBG = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocRBG = pViewRBG->GetDocument();
	pDocRBG->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF PixelColorOne;
	int nROne;	int nGOne;	int nBOne;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX++)
		{

			nROne = 0;	nGOne = 0;	nBOne = 0;
			PixelColorOne = pDoc->m_ImageOpen.GetPixel(nX, nY);
			nROne = GetRValue(PixelColorOne);
			nGOne = GetGValue(PixelColorOne);
			nBOne = GetBValue(PixelColorOne);
			pDocRBG->m_ImageOpen.SetPixel(nX, nY, RGB(nROne, nBOne, nGOne));
		}
	}

	pViewRBG->OnInitialUpdate();
}


void CMFCAppView::OnRgbswapBgr()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewBGR = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocBGR = pViewBGR->GetDocument();
	pDocBGR->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF PixelColorOne;
	int nROne;	int nGOne;	int nBOne;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX++)
		{

			nROne = 0;	nGOne = 0;	nBOne = 0;
			PixelColorOne = pDoc->m_ImageOpen.GetPixel(nX, nY);
			nROne = GetRValue(PixelColorOne);
			nGOne = GetGValue(PixelColorOne);
			nBOne = GetBValue(PixelColorOne);
			pDocBGR->m_ImageOpen.SetPixel(nX, nY, RGB(nBOne, nGOne, nROne));
		}
	}

	pViewBGR->OnInitialUpdate();
}


void CMFCAppView::OnRgbswapBrg()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewBRG = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocBRG = pViewBRG->GetDocument();
	pDocBRG->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF PixelColorOne;
	int nROne;	int nGOne;	int nBOne;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX++)
		{

			nROne = 0;	nGOne = 0;	nBOne = 0;
			PixelColorOne = pDoc->m_ImageOpen.GetPixel(nX, nY);
			nROne = GetRValue(PixelColorOne);
			nGOne = GetGValue(PixelColorOne);
			nBOne = GetBValue(PixelColorOne);
			pDocBRG->m_ImageOpen.SetPixel(nX, nY, RGB(nBOne, nROne, nGOne));
		}
	}

	pViewBRG->OnInitialUpdate();
}


void CMFCAppView::OnRgbswapGrb()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewGRB = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocGRB = pViewGRB->GetDocument();
	pDocGRB->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF PixelColorOne;
	int nROne;	int nGOne;	int nBOne;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX++)
		{

			nROne = 0;	nGOne = 0;	nBOne = 0;
			PixelColorOne = pDoc->m_ImageOpen.GetPixel(nX, nY);
			nROne = GetRValue(PixelColorOne);
			nGOne = GetGValue(PixelColorOne);
			nBOne = GetBValue(PixelColorOne);
			pDocGRB->m_ImageOpen.SetPixel(nX, nY, RGB(nGOne, nROne, nBOne));
		}
	}

	pViewGRB->OnInitialUpdate();
}


void CMFCAppView::OnRgbswapGbr()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewGBR = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocGBR = pViewGBR->GetDocument();
	pDocGBR->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF PixelColorOne;
	int nROne;	int nGOne;	int nBOne;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX++)
		{

			nROne = 0;	nGOne = 0;	nBOne = 0;
			PixelColorOne = pDoc->m_ImageOpen.GetPixel(nX, nY);
			nROne = GetRValue(PixelColorOne);
			nGOne = GetGValue(PixelColorOne);
			nBOne = GetBValue(PixelColorOne);
			pDocGBR->m_ImageOpen.SetPixel(nX, nY, RGB(nGOne, nBOne, nROne));
		}
	}

	pViewGBR->OnInitialUpdate();
}


void CMFCAppView::OnCmykC()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewCMYKc = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocCMYKc = pViewCMYKc->GetDocument();
	pDocCMYKc->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;
	int nG;
	int nB;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);

			nR = GetRValue(ColorRefOne);
			nG = GetGValue(ColorRefOne);
			nB = GetBValue(ColorRefOne);

			pDocCMYKc->m_ImageOpen.SetPixel(nX, nY, RGB(0, nG, nB));
		}
	}

	pViewCMYKc->OnInitialUpdate();
	pDocCMYKc->UpdateAllViews(pViewCMYKc);

}


void CMFCAppView::OnCmykM()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewCMYKm = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocCMYKm = pViewCMYKm->GetDocument();
	pDocCMYKm->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;
	int nG;
	int nB;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);

			nR = GetRValue(ColorRefOne);
			nG = GetGValue(ColorRefOne);
			nB = GetBValue(ColorRefOne);

			//pDocCMYKc->m_ImageOpen.SetPixel(nX, nY, RGB(0, nG, nB));
			pDocCMYKm->m_ImageOpen.SetPixel(nX, nY, RGB(nR, 0, nB));
			//pDocYellow->m_ImageOne.SetPixel(nX, nY, RGB(nR, nG, 0));
		}
	}

	pViewCMYKm->OnInitialUpdate();
	pDocCMYKm->UpdateAllViews(pViewCMYKm);
}


void CMFCAppView::OnCmykY()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewCMYKy = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocCMYKy = pViewCMYKy->GetDocument();
	pDocCMYKy->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;
	int nG;
	int nB;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);

			nR = GetRValue(ColorRefOne);
			nG = GetGValue(ColorRefOne);
			nB = GetBValue(ColorRefOne);

			//pDocCMYKc->m_ImageOpen.SetPixel(nX, nY, RGB(0, nG, nB));
			//pDocMagenta->m_ImageOne.SetPixel(nX, nY, RGB(nR, 0, nB));
			pDocCMYKy->m_ImageOpen.SetPixel(nX, nY, RGB(nR, nG, 0));
		}
	}

	pViewCMYKy->OnInitialUpdate();
	pDocCMYKy->UpdateAllViews(pViewCMYKy);
}


void CMFCAppView::OnYiqY()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewYIQy = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocYIQy = pViewYIQy->GetDocument();
	pDocYIQy->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;
	int nG;
	int nB;

	int nYIQY;
	int nYIQI;
	int nYIQQ;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);
			nR = GetRValue(ColorRefOne);
			nG = GetGValue(ColorRefOne);
			nB = GetBValue(ColorRefOne);

			nYIQY = int(nR * 0.299 + nG * 0.587 + nB * 0.114);
			pDocYIQy->m_ImageOpen.SetPixel(nX, nY, RGB(nYIQY, nYIQY, nYIQY));

			/*nYIQI = int(nR * 0.596 - nG * 0.274 - nB * 0.322);
			if (nYIQI > 255)
			{
				nYIQI = 255;
			}
			if (nYIQI < 0)
			{
				nYIQI = 0;
			}
			pDocI->m_ImageOne.SetPixel(nX, nY, RGB(nYIQI, nYIQI, nYIQI));

			nYIQQ = int(nR * 0.211 - nG * 0.523 + nB * 0.312);
			if (nYIQQ > 255)
			{
				nYIQQ = 255;
			}
			if (nYIQQ < 0)
			{
				nYIQQ = 0;
			}
			pDocQ->m_ImageOne.SetPixel(nX, nY, RGB(nYIQQ, nYIQQ, nYIQQ));*/
		}
	}

	pViewYIQy->OnInitialUpdate();
	pDocYIQy->UpdateAllViews(pViewYIQy);

}


void CMFCAppView::OnYiqI()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewYIQi = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocYIQi = pViewYIQi->GetDocument();
	pDocYIQi->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;
	int nG;
	int nB;

	int nYIQY;
	int nYIQI;
	int nYIQQ;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);
			nR = GetRValue(ColorRefOne);
			nG = GetGValue(ColorRefOne);
			nB = GetBValue(ColorRefOne);

			/*nYIQY = int(nR * 0.299 + nG * 0.587 + nB * 0.114);
			pDocYIQy->m_ImageOpen.SetPixel(nX, nY, RGB(nYIQY, nYIQY, nYIQY));*/

			nYIQI = int(nR * 0.596 - nG * 0.274 - nB * 0.322);
			if (nYIQI > 255)
			{
				nYIQI = 255;
			}
			if (nYIQI < 0)
			{
				nYIQI = 0;
			}
			pDocYIQi->m_ImageOpen.SetPixel(nX, nY, RGB(nYIQI, nYIQI, nYIQI));

			/*nYIQQ = int(nR * 0.211 - nG * 0.523 + nB * 0.312);
			if (nYIQQ > 255)
			{
				nYIQQ = 255;
			}
			if (nYIQQ < 0)
			{
				nYIQQ = 0;
			}
			pDocQ->m_ImageOne.SetPixel(nX, nY, RGB(nYIQQ, nYIQQ, nYIQQ));*/
		}
	}

	pViewYIQi->OnInitialUpdate();
	pDocYIQi->UpdateAllViews(pViewYIQi);
}


void CMFCAppView::OnYiqQ()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewYIQq = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocYIQq = pViewYIQq->GetDocument();
	pDocYIQq->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;
	int nG;
	int nB;

	int nYIQY;
	int nYIQI;
	int nYIQQ;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);
			nR = GetRValue(ColorRefOne);
			nG = GetGValue(ColorRefOne);
			nB = GetBValue(ColorRefOne);

			/*nYIQY = int(nR * 0.299 + nG * 0.587 + nB * 0.114);
			pDocYIQy->m_ImageOpen.SetPixel(nX, nY, RGB(nYIQY, nYIQY, nYIQY));*/

			/*nYIQI = int(nR * 0.596 - nG * 0.274 - nB * 0.322);
			if (nYIQI > 255)
			{
				nYIQI = 255;
			}
			if (nYIQI < 0)
			{
				nYIQI = 0;
			}
			pDocI->m_ImageOne.SetPixel(nX, nY, RGB(nYIQI, nYIQI, nYIQI));*/

			nYIQQ = int(nR * 0.211 - nG * 0.523 + nB * 0.312);
			if (nYIQQ > 255)
			{
				nYIQQ = 255;
			}
			if (nYIQQ < 0)
			{
				nYIQQ = 0;
			}
			pDocYIQq->m_ImageOpen.SetPixel(nX, nY, RGB(nYIQQ, nYIQQ, nYIQQ));
		}
	}

	pViewYIQq->OnInitialUpdate();
	pDocYIQq->UpdateAllViews(pViewYIQq);
}


void CMFCAppView::OnColorHsv()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	float H_add = 0.49;
	CDialogHue HueLevelOne;
	HueLevelOne.HueLevel = H_add;
	if (HueLevelOne.DoModal() == IDOK) {
		H_add = HueLevelOne.HueLevel;
	}
	else
	{
		return;
	}

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewHSV = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocHSV = pViewHSV->GetDocument();
	pDocHSV->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int R;
	int G;
	int B;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);
			R = GetRValue(ColorRefOne);
			G = GetGValue(ColorRefOne);
			B = GetBValue(ColorRefOne);
			// R, G, B [0, 255] 
			float H = 0, S = 0, V = 0;
			float cMax = 255.0;
			int cHi = max(R, max(G, B)); //highest color value 
			int cLo = min(R, min(G, B)); //lowest color value 
			int cRng = cHi - cLo; // color range 
			// compute value V
			V = cHi / cMax;

			// compute saturation S 
			if (cHi > 0)
				S = (float)cRng / cHi;
			// compute hue H 
			if (cRng > 0)
			{ // hue is defined only for color pixels 
				float rr = (float)(cHi - R) / cRng; 	float gg = (float)(cHi - G) / cRng; 	float bb = (float)(cHi - B) / cRng;
				float hh;
				if (R == cHi)
				{
					hh = bb - gg;
				}
				else
				{
					if (G == cHi)
					{
						hh = rr - bb + 2.0;
					}
					else
					{
						hh = gg - rr + 4.0;
					}
				}
				if (hh < 0)
				{
					hh = hh + 6;
				}
				H = hh / 6;
			}
			//inverse 
			H = H + H_add;
			float rr = 0, gg = 0, bb = 0;
			float hh = fmod((6 * H), 6); // h! <- (6 • h) mod 6 
			int cl = (int)hh; // c\ <- \hl\ 
			float c2 = hh - cl;
			float x = (1 - S) * V;
			float y = (1 - (S * c2)) * V;
			float z = (1 - (S * (1 - c2))) * V;
			switch (cl) {
				case 0: rr = V; gg = z; bb = x; break;
				case 1: rr = y; gg = V; bb = x; break;
				case 2: rr = x; gg = V; bb = z; break;
				case 3: rr = x; gg = y; bb = V; break;
				case 4: rr = z; gg = x; bb = V; break;
				case 5: rr = V; gg = x; bb = y; break;
			}
			int N = 256;
			int r = min(floor(rr * N + 0.5), N - 1);
			//r=(r&0xff)<<16;
			int g = min(floor(gg * N + 0.5), N - 1);
			//g=(g&0xff)<<8;
			int b = min(floor(bb * N + 0.5), N - 1);
			//b=(b&0xff);
			pDocHSV->m_ImageOpen.SetPixel(nX, nY, RGB(r, g, b));
		}
	}

	pViewHSV->OnInitialUpdate();
	pDocHSV->UpdateAllViews(pViewHSV);

}


void CMFCAppView::OnGrayR()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewGrayR = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocGrayR = pViewGrayR->GetDocument();
	pDocGrayR->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;
	int nG;
	int nB;

	byte byGray;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);

			nR = GetRValue(ColorRefOne);
			//nG = GetGValue(ColorRefOne);
			//nB = GetBValue(ColorRefOne);

			byGray = nR;

			pDocGrayR->m_ImageOpen.SetPixel(nX, nY, RGB(byGray, byGray, byGray));
		}
	}

	pViewGrayR->OnInitialUpdate();
	pFrame->SendMessage(WM_COMMAND, ID_WINDOW_TILE_HORZ);

}


void CMFCAppView::OnGrayG()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewGrayG = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocGrayG = pViewGrayG->GetDocument();
	pDocGrayG->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;
	int nG;
	int nB;

	byte byGray;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);

			//nR = GetRValue(ColorRefOne);
			nG = GetGValue(ColorRefOne);
			//nB = GetBValue(ColorRefOne);

			byGray = nG;

			pDocGrayG->m_ImageOpen.SetPixel(nX, nY, RGB(byGray, byGray, byGray));
		}
	}

	pViewGrayG->OnInitialUpdate();
	pFrame->SendMessage(WM_COMMAND, ID_WINDOW_TILE_HORZ);

}


void CMFCAppView::OnGrayB()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewGrayB = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocGrayB = pViewGrayB->GetDocument();
	pDocGrayB->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;
	int nG;
	int nB;

	byte byGray;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);

			//nR = GetRValue(ColorRefOne);
			//nG = GetGValue(ColorRefOne);
			nB = GetBValue(ColorRefOne);

			byGray = nB;

			pDocGrayB->m_ImageOpen.SetPixel(nX, nY, RGB(byGray, byGray, byGray));
		}
	}

	pViewGrayB->OnInitialUpdate();
	pFrame->SendMessage(WM_COMMAND, ID_WINDOW_TILE_HORZ);
}


void CMFCAppView::OnGrayRg()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewGrayRG = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocGrayRG = pViewGrayRG->GetDocument();
	pDocGrayRG->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;
	int nG;
	int nB;

	byte byGray;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);

			nR = GetRValue(ColorRefOne);
			nG = GetGValue(ColorRefOne);
			//nB = GetBValue(ColorRefOne);

			byGray = (nR + nG) / 2;

			pDocGrayRG->m_ImageOpen.SetPixel(nX, nY, RGB(byGray, byGray, byGray));
		}
	}

	pViewGrayRG->OnInitialUpdate();
	pFrame->SendMessage(WM_COMMAND, ID_WINDOW_TILE_HORZ);
}


void CMFCAppView::OnGrayGb()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewGrayGB = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocGrayGB = pViewGrayGB->GetDocument();
	pDocGrayGB->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;
	int nG;
	int nB;

	byte byGray;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);

			//nR = GetRValue(ColorRefOne);
			nG = GetGValue(ColorRefOne);
			nB = GetBValue(ColorRefOne);

			byGray = (nG + nB) / 2;

			pDocGrayGB->m_ImageOpen.SetPixel(nX, nY, RGB(byGray, byGray, byGray));
		}
	}

	pViewGrayGB->OnInitialUpdate();
	pFrame->SendMessage(WM_COMMAND, ID_WINDOW_TILE_HORZ);
}


void CMFCAppView::OnGrayBr()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewGrayBR = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocGrayBR = pViewGrayBR->GetDocument();
	pDocGrayBR->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;
	int nG;
	int nB;

	byte byGray;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);

			nR = GetRValue(ColorRefOne);
			//nG = GetGValue(ColorRefOne);
			nB = GetBValue(ColorRefOne);

			byGray = (nB + nR) / 2;

			pDocGrayBR->m_ImageOpen.SetPixel(nX, nY, RGB(byGray, byGray, byGray));
		}
	}

	pViewGrayBR->OnInitialUpdate();
	pFrame->SendMessage(WM_COMMAND, ID_WINDOW_TILE_HORZ);
}


void CMFCAppView::OnGrayMin()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewGrayMin = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocGrayMin = pViewGrayMin->GetDocument();
	pDocGrayMin->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;
	int nG;
	int nB;

	byte byGray;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);

			nR = GetRValue(ColorRefOne);
			nG = GetGValue(ColorRefOne);
			nB = GetBValue(ColorRefOne);

			byGray = min(nR, min(nG, nB));

			pDocGrayMin->m_ImageOpen.SetPixel(nX, nY, RGB(byGray, byGray, byGray));
		}
	}

	pViewGrayMin->OnInitialUpdate();
	pFrame->SendMessage(WM_COMMAND, ID_WINDOW_TILE_HORZ);
}


void CMFCAppView::OnGrayMax()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewGrayMax = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocGrayMax = pViewGrayMax->GetDocument();
	pDocGrayMax->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;
	int nG;
	int nB;

	byte byGray;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);

			nR = GetRValue(ColorRefOne);
			nG = GetGValue(ColorRefOne);
			nB = GetBValue(ColorRefOne);

			byGray = max(nR, max(nG, nB));

			pDocGrayMax->m_ImageOpen.SetPixel(nX, nY, RGB(byGray, byGray, byGray));
		}
	}

	pViewGrayMax->OnInitialUpdate();
	pFrame->SendMessage(WM_COMMAND, ID_WINDOW_TILE_HORZ);
}


void CMFCAppView::OnGrayMiddle()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewGrayMid = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocGrayMid = pViewGrayMid->GetDocument();
	pDocGrayMid->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;
	int nG;
	int nB;
	int Max;
	int Min;

	byte byGray;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);

			nR = GetRValue(ColorRefOne);
			nG = GetGValue(ColorRefOne);
			nB = GetBValue(ColorRefOne);
			Max = max(nR, max(nG, nB));
			Min = min(nR, min(nG, nB));
			if (nR != Max && nR != Min) {
				byGray = nR;
			}
			if (nG != Max && nG != Min) {
				byGray = nG;
			}
			if (nB != Max && nB != Min) {
				byGray = nB;
			}

			pDocGrayMid->m_ImageOpen.SetPixel(nX, nY, RGB(byGray, byGray, byGray));
		}
	}

	pViewGrayMid->OnInitialUpdate();
	pFrame->SendMessage(WM_COMMAND, ID_WINDOW_TILE_HORZ);
}


void CMFCAppView::OnGrayK()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewGrayK = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocGrayK = pViewGrayK->GetDocument();
	pDocGrayK->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;
	int nG;
	int nB;

	byte byGray;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);

			nR = GetRValue(ColorRefOne);
			nG = GetGValue(ColorRefOne);
			nB = GetBValue(ColorRefOne);

			byGray = min((255 - nR), min((255 - nG), (255 - nB)));

			pDocGrayK->m_ImageOpen.SetPixel(nX, nY, RGB(byGray, byGray, byGray));
		}
	}

	pViewGrayK->OnInitialUpdate();
	pFrame->SendMessage(WM_COMMAND, ID_WINDOW_TILE_HORZ);
}


void CMFCAppView::OnGrayY()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewGrayY = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocGrayY = pViewGrayY->GetDocument();
	pDocGrayY->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;
	int nG;
	int nB;

	byte byGray;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);

			nR = GetRValue(ColorRefOne);
			nG = GetGValue(ColorRefOne);
			nB = GetBValue(ColorRefOne);

			byGray = 0.299 * nR + 0.587 * nG + 0.114 * nB;

			pDocGrayY->m_ImageOpen.SetPixel(nX, nY, RGB(byGray, byGray, byGray));
		}
	}

	pViewGrayY->OnInitialUpdate();
	pFrame->SendMessage(WM_COMMAND, ID_WINDOW_TILE_HORZ);
}


void CMFCAppView::OnGrayI()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewGrayI = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocGrayI = pViewGrayI->GetDocument();
	pDocGrayI->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;
	int nG;
	int nB;

	byte byGray;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);

			nR = GetRValue(ColorRefOne);
			nG = GetGValue(ColorRefOne);
			nB = GetBValue(ColorRefOne);

			byGray = (nR + nG + nB) / 3;

			pDocGrayI->m_ImageOpen.SetPixel(nX, nY, RGB(byGray, byGray, byGray));
		}
	}

	pViewGrayI->OnInitialUpdate();
	pFrame->SendMessage(WM_COMMAND, ID_WINDOW_TILE_HORZ);
}



void CMFCAppView::OnGrayL()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewGrayL = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocGrayL= pViewGrayL->GetDocument();
	pDocGrayL->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;
	int nG;
	int nB;

	byte byGray;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);

			nR = GetRValue(ColorRefOne);
			nG = GetGValue(ColorRefOne);
			nB = GetBValue(ColorRefOne);

			byGray = (max(nR, nG, nB) + min(nR, nG, nB)) / 2;

			pDocGrayL->m_ImageOpen.SetPixel(nX, nY, RGB(byGray, byGray, byGray));
		}
	}

	pViewGrayL->OnInitialUpdate();
	pFrame->SendMessage(WM_COMMAND, ID_WINDOW_TILE_HORZ);
}


void CMFCAppView::OnGrayV()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewGrayV = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocGrayV = pViewGrayV->GetDocument();
	pDocGrayV->m_ImageOpen.Create(
		pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(),
		24);

	int nX; int nY;
	COLORREF ColorRefOne;

	int nR;
	int nG;
	int nB;

	byte byGray;

	for (nY = 0; nY < pDoc->m_ImageOpen.GetHeight(); nY = nY + 1)
	{
		for (nX = 0; nX < pDoc->m_ImageOpen.GetWidth(); nX = nX + 1)
		{
			ColorRefOne = pDoc->m_ImageOpen.GetPixel(nX, nY);

			nR = GetRValue(ColorRefOne);
			nG = GetGValue(ColorRefOne);
			nB = GetBValue(ColorRefOne);

			byGray = max(nR, nG, nB) / 255 * 255;

			pDocGrayV->m_ImageOpen.SetPixel(nX, nY, RGB(byGray, byGray, byGray));
		}
	}

	pViewGrayV->OnInitialUpdate();
	pFrame->SendMessage(WM_COMMAND, ID_WINDOW_TILE_HORZ);
}


void CMFCAppView::OnArithmeticAdd()
{
	// TODO: 在此添加命令处理程序代码
	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);

	CMFCAppView* pView = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDoc = pView->GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	pFrame->SendMessage(WM_COMMAND, ID_FILE_OPEN);
	CMFCAppView* pViewAnother = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocAnother = pViewAnother->GetDocument();

	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();

	pDocNew->m_ImageOpen.Create(max(pDoc->m_ImageOpen.GetWidth(), pDocAnother->m_ImageOpen.GetWidth()),
		max(pDoc->m_ImageOpen.GetHeight(), pDocAnother->m_ImageOpen.GetHeight()), 24);

	int nX; int nY;
	COLORREF PixelColorOne;
	COLORREF PixelColorAnother;
	int nROne; int nGOne; int nBOne;
	int nRAnother; int nGAnother; int nBAnother;
	int nRSum; int nGSum; int nBSum;

	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{
			nROne = 0; nGOne = 0; nBOne = 0;
			if (nX < pDoc->m_ImageOpen.GetWidth())
			{
				if (nY < pDoc->m_ImageOpen.GetHeight())
				{
					PixelColorOne = pDoc->m_ImageOpen.GetPixel(nX, nY);
					nROne = GetRValue(PixelColorOne);
					nGOne = GetGValue(PixelColorOne);
					nBOne = GetBValue(PixelColorOne);
				}
			}
			nRAnother = 0; nGAnother = 0; nBAnother = 0;
			if (nX < pDocAnother->m_ImageOpen.GetWidth())
			{
				if (nY < pDocAnother->m_ImageOpen.GetHeight())
				{
					PixelColorAnother = pDocAnother->m_ImageOpen.GetPixel(nX, nY);
					nRAnother = GetRValue(PixelColorAnother);
					nGAnother = GetGValue(PixelColorAnother);
					nBAnother = GetBValue(PixelColorAnother);
				}
			}
			nRSum = nROne + nRAnother;
			if (nRSum > 255)
			{
				nRSum = 255;
			}
			nGSum = nGOne + nGAnother;
			if (nGSum > 255)
			{
				nGSum = 255;
			}
			nBSum = nBOne + nBAnother;
			if (nBSum > 255)
			{
				nBSum = 255;
			}
			pDocNew->m_ImageOpen.SetPixel(nX, nY, RGB(nRSum, nGSum, nBSum));
		}
	}

	pViewNew->OnInitialUpdate();
	pDocNew->UpdateAllViews(pViewNew);

}


void CMFCAppView::OnArithmeticSubstract()
{
	// TODO: 在此添加命令处理程序代码
	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);

	CMFCAppView* pView = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDoc = pView->GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	pFrame->SendMessage(WM_COMMAND, ID_FILE_OPEN);
	CMFCAppView* pViewAnother = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocAnother = pViewAnother->GetDocument();

	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();

	pDocNew->m_ImageOpen.Create(max(pDoc->m_ImageOpen.GetWidth(), pDocAnother->m_ImageOpen.GetWidth()),
		max(pDoc->m_ImageOpen.GetHeight(), pDocAnother->m_ImageOpen.GetHeight()), 24);

	int nX; int nY;
	COLORREF PixelColorOne;
	COLORREF PixelColorAnother;
	int nROne; int nGOne; int nBOne;
	int nRAnother; int nGAnother; int nBAnother;
	int nRSubtract; int nGSubtract; int nBSubtract;

	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{
			nROne = 0; nGOne = 0; nBOne = 0;
			if (nX < pDoc->m_ImageOpen.GetWidth())
			{
				if (nY < pDoc->m_ImageOpen.GetHeight())
				{
					PixelColorOne = pDoc->m_ImageOpen.GetPixel(nX, nY);
					nROne = GetRValue(PixelColorOne);
					nGOne = GetGValue(PixelColorOne);
					nBOne = GetBValue(PixelColorOne);
				}
			}
			nRAnother = 0; nGAnother = 0; nBAnother = 0;
			if (nX < pDocAnother->m_ImageOpen.GetWidth())
			{
				if (nY < pDocAnother->m_ImageOpen.GetHeight())
				{
					PixelColorAnother = pDocAnother->m_ImageOpen.GetPixel(nX, nY);
					nRAnother = GetRValue(PixelColorAnother);
					nGAnother = GetGValue(PixelColorAnother);
					nBAnother = GetBValue(PixelColorAnother);
				}
			}
			nRSubtract = nROne - nRAnother;
			if (nRSubtract < 0)
			{
				nRSubtract = 0;
			}
			nGSubtract = nGOne - nGAnother;
			if (nGSubtract < 0)
			{
				nGSubtract = 0;
			}
			nBSubtract = nBOne - nBAnother;
			if (nBSubtract < 0)
			{
				nBSubtract = 0;
			}
			pDocNew->m_ImageOpen.SetPixel(nX, nY, RGB(nRSubtract, nGSubtract, nBSubtract));
		}
	}

	pViewNew->OnInitialUpdate();
}


void CMFCAppView::OnArithmeticMultiply()
{
	// TODO: 在此添加命令处理程序代码
	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);

	CMFCAppView* pView = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDoc = pView->GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	pFrame->SendMessage(WM_COMMAND, ID_FILE_OPEN);
	CMFCAppView* pViewAnother = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocAnother = pViewAnother->GetDocument();

	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();

	pDocNew->m_ImageOpen.Create(max(pDoc->m_ImageOpen.GetWidth(), pDocAnother->m_ImageOpen.GetWidth()),
		max(pDoc->m_ImageOpen.GetHeight(), pDocAnother->m_ImageOpen.GetHeight()), 24);

	int nX; int nY;
	COLORREF PixelColorOne;
	COLORREF PixelColorAnother;
	int nROne; int nGOne; int nBOne;
	int nRAnother; int nGAnother; int nBAnother;
	int nRProduct; int nGProduct; int nBProduct;

	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{
			nROne = 0; nGOne = 0; nBOne = 0;
			if (nX < pDoc->m_ImageOpen.GetWidth())
			{
				if (nY < pDoc->m_ImageOpen.GetHeight())
				{
					PixelColorOne = pDoc->m_ImageOpen.GetPixel(nX, nY);
					nROne = GetRValue(PixelColorOne);
					nGOne = GetGValue(PixelColorOne);
					nBOne = GetBValue(PixelColorOne);
				}
			}
			nRAnother = 0; nGAnother = 0; nBAnother = 0;
			if (nX < pDocAnother->m_ImageOpen.GetWidth())
			{
				if (nY < pDocAnother->m_ImageOpen.GetHeight())
				{
					PixelColorAnother = pDocAnother->m_ImageOpen.GetPixel(nX, nY);
					nRAnother = GetRValue(PixelColorAnother);
					nGAnother = GetGValue(PixelColorAnother);
					nBAnother = GetBValue(PixelColorAnother);
				}
			}
			nRProduct = nROne * nRAnother / 255;
			nGProduct = nGOne * nGAnother / 255;
			nBProduct = nBOne * nBAnother / 255;

			pDocNew->m_ImageOpen.SetPixel(nX, nY, RGB(nRProduct, nGProduct, nBProduct));

		}
	}

	pViewNew->OnInitialUpdate();
}


void CMFCAppView::OnArithmeticDivide()
{
	// TODO: 在此添加命令处理程序代码
	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);

	CMFCAppView* pView = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDoc = pView->GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	pFrame->SendMessage(WM_COMMAND, ID_FILE_OPEN);
	CMFCAppView* pViewAnother = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocAnother = pViewAnother->GetDocument();

	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();

	pDocNew->m_ImageOpen.Create(max(pDoc->m_ImageOpen.GetWidth(), pDocAnother->m_ImageOpen.GetWidth()),
		max(pDoc->m_ImageOpen.GetHeight(), pDocAnother->m_ImageOpen.GetHeight()), 24);

	int nX; int nY;
	COLORREF PixelColorOne;
	COLORREF PixelColorAnother;
	int nROne; int nGOne; int nBOne;
	int nRAnother; int nGAnother; int nBAnother;
	int nRQuotient; int nGQuotient; int nBQuotient;

	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{
			nROne = 0; nGOne = 0; nBOne = 0;
			if (nX < pDoc->m_ImageOpen.GetWidth())
			{
				if (nY < pDoc->m_ImageOpen.GetHeight())
				{
					PixelColorOne = pDoc->m_ImageOpen.GetPixel(nX, nY);
					nROne = GetRValue(PixelColorOne);
					nGOne = GetGValue(PixelColorOne);
					nBOne = GetBValue(PixelColorOne);
				}
			}
			nRAnother = 0; nGAnother = 0; nBAnother = 0;
			if (nX < pDocAnother->m_ImageOpen.GetWidth())
			{
				if (nY < pDocAnother->m_ImageOpen.GetHeight())
				{
					PixelColorAnother = pDocAnother->m_ImageOpen.GetPixel(nX, nY);
					nRAnother = GetRValue(PixelColorAnother);
					nGAnother = GetGValue(PixelColorAnother);
					nBAnother = GetBValue(PixelColorAnother);
				}
			}
			if (nRAnother < 1)
			{
				continue;
			}
			if (nGAnother < 1)
			{
				continue;
			}
			if (nBAnother < 1)
			{
				continue;
			}
			nRQuotient = nROne / nRAnother * 255;
			nGQuotient = nGOne / nGAnother * 255;
			nBQuotient = nBOne / nBAnother * 255;
			pDocNew->m_ImageOpen.SetPixel(nX, nY,
				RGB(nRQuotient, nGQuotient, nBQuotient));
		}
	}

	pViewNew->OnInitialUpdate();
}


void CMFCAppView::OnVectorText()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	CString StringOne;
	CDialogText DialogTextOne;
	int BKColorR, BKColorG, BKColorB;
	int TextColorR, TextColorG, TextColorB;

	DialogTextOne.m_nBKColor_R = BKColorR = 0;
	DialogTextOne.m_nBKColor_G = BKColorG = 255;
	DialogTextOne.m_nBKColor_B = BKColorB = 0;
	DialogTextOne.m_nTextColor_R = TextColorR = 255;
	DialogTextOne.m_nTextColor_G = TextColorG = 0;
	DialogTextOne.m_nTextColor_B = TextColorB = 255;

	if (DialogTextOne.DoModal() == IDOK) {
		StringOne = DialogTextOne.m_nText;
		BKColorR = DialogTextOne.m_nBKColor_R;
		BKColorG = DialogTextOne.m_nBKColor_G;
		BKColorB = DialogTextOne.m_nBKColor_B;
		TextColorR = DialogTextOne.m_nTextColor_R;
		TextColorG = DialogTextOne.m_nTextColor_G;
		TextColorB = DialogTextOne.m_nTextColor_B;
	}
	else {
		return;
	}
	CDC* pDC;
	pDC = CDC::FromHandle(pDoc->m_ImageOpen.GetDC());

	pDC->SetBkColor(RGB(BKColorR, BKColorG, BKColorB));
	pDC->SetTextColor(RGB(TextColorR, TextColorG, TextColorB));

	pDC->DrawText(StringOne, StringOne.GetLength(), CRect(0, 0, pDoc->m_ImageOpen.GetWidth(), 40),
		DT_CENTER);
	pDoc->m_ImageOpen.ReleaseDC();
	Invalidate();

}


void CMFCAppView::OnArithmeticLighten()
{
	// TODO: 在此添加命令处理程序代码
	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);

	CMFCAppView* pView = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDoc = pView->GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	pFrame->SendMessage(WM_COMMAND, ID_FILE_OPEN);
	CMFCAppView* pViewAnother = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocAnother = pViewAnother->GetDocument();

	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();

	pDocNew->m_ImageOpen.Create(max(pDoc->m_ImageOpen.GetWidth(), pDocAnother->m_ImageOpen.GetWidth()),
		max(pDoc->m_ImageOpen.GetHeight(), pDocAnother->m_ImageOpen.GetHeight()), 24);

	int nX; int nY;
	COLORREF PixelColorOne;
	COLORREF PixelColorAnother;
	int nROne; int nGOne; int nBOne;
	int nRAnother; int nGAnother; int nBAnother;
	int nRNew, nGNew, nBNew;

	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{
			nROne = 0; nGOne = 0; nBOne = 0;
			if (nX < pDoc->m_ImageOpen.GetWidth())
			{
				if (nY < pDoc->m_ImageOpen.GetHeight())
				{
					PixelColorOne = pDoc->m_ImageOpen.GetPixel(nX, nY);
					nROne = GetRValue(PixelColorOne);
					nGOne = GetGValue(PixelColorOne);
					nBOne = GetBValue(PixelColorOne);
				}
			}
			nRAnother = 0; nGAnother = 0; nBAnother = 0;
			if (nX < pDocAnother->m_ImageOpen.GetWidth())
			{
				if (nY < pDocAnother->m_ImageOpen.GetHeight())
				{
					PixelColorAnother = pDocAnother->m_ImageOpen.GetPixel(nX, nY);
					nRAnother = GetRValue(PixelColorAnother);
					nGAnother = GetGValue(PixelColorAnother);
					nBAnother = GetBValue(PixelColorAnother);
				}
			}
			nRNew = max(nROne, nRAnother);
			nGNew = max(nGOne, nGAnother);
			nBNew = max(nBOne, nBAnother);

			pDocNew->m_ImageOpen.SetPixel(nX, nY,
				RGB(nRNew,nGNew,nBNew));
		}
	}

	pViewNew->OnInitialUpdate();
}


void CMFCAppView::OnArithmeticDarken()
{
	// TODO: 在此添加命令处理程序代码
	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);

	CMFCAppView* pView = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDoc = pView->GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	pFrame->SendMessage(WM_COMMAND, ID_FILE_OPEN);
	CMFCAppView* pViewAnother = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocAnother = pViewAnother->GetDocument();

	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();

	pDocNew->m_ImageOpen.Create(max(pDoc->m_ImageOpen.GetWidth(), pDocAnother->m_ImageOpen.GetWidth()),
		max(pDoc->m_ImageOpen.GetHeight(), pDocAnother->m_ImageOpen.GetHeight()), 24);

	int nX; int nY;
	COLORREF PixelColorOne;
	COLORREF PixelColorAnother;
	int nROne; int nGOne; int nBOne;
	int nRAnother; int nGAnother; int nBAnother;
	int nRNew, nGNew, nBNew;

	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{
			nROne = 0; nGOne = 0; nBOne = 0;
			if (nX < pDoc->m_ImageOpen.GetWidth())
			{
				if (nY < pDoc->m_ImageOpen.GetHeight())
				{
					PixelColorOne = pDoc->m_ImageOpen.GetPixel(nX, nY);
					nROne = GetRValue(PixelColorOne);
					nGOne = GetGValue(PixelColorOne);
					nBOne = GetBValue(PixelColorOne);
				}
			}
			nRAnother = 0; nGAnother = 0; nBAnother = 0;
			if (nX < pDocAnother->m_ImageOpen.GetWidth())
			{
				if (nY < pDocAnother->m_ImageOpen.GetHeight())
				{
					PixelColorAnother = pDocAnother->m_ImageOpen.GetPixel(nX, nY);
					nRAnother = GetRValue(PixelColorAnother);
					nGAnother = GetGValue(PixelColorAnother);
					nBAnother = GetBValue(PixelColorAnother);
				}
			}
			nRNew = min(nROne, nRAnother);
			nGNew = min(nGOne, nGAnother);
			nBNew = min(nBOne, nBAnother);

			pDocNew->m_ImageOpen.SetPixel(nX, nY,
				RGB(nRNew, nGNew, nBNew));
		}
	}

	pViewNew->OnInitialUpdate();
}



void CMFCAppView::OnArithmeticLinerlight()
{
	// TODO: 在此添加命令处理程序代码
	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);

	CMFCAppView* pView = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDoc = pView->GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	pFrame->SendMessage(WM_COMMAND, ID_FILE_OPEN);
	CMFCAppView* pViewAnother = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocAnother = pViewAnother->GetDocument();

	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();

	pDocNew->m_ImageOpen.Create(max(pDoc->m_ImageOpen.GetWidth(), pDocAnother->m_ImageOpen.GetWidth()),
		max(pDoc->m_ImageOpen.GetHeight(), pDocAnother->m_ImageOpen.GetHeight()), 24);

	int nX; int nY;
	COLORREF PixelColorOne;
	COLORREF PixelColorAnother;
	int nROne; int nGOne; int nBOne;
	int nRAnother; int nGAnother; int nBAnother;
	int nRNew, nGNew, nBNew;

	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{
			nROne = 0; nGOne = 0; nBOne = 0;
			if (nX < pDoc->m_ImageOpen.GetWidth())
			{
				if (nY < pDoc->m_ImageOpen.GetHeight())
				{
					PixelColorOne = pDoc->m_ImageOpen.GetPixel(nX, nY);
					nROne = GetRValue(PixelColorOne);
					nGOne = GetGValue(PixelColorOne);
					nBOne = GetBValue(PixelColorOne);
				}
			}
			nRAnother = 0; nGAnother = 0; nBAnother = 0;
			if (nX < pDocAnother->m_ImageOpen.GetWidth())
			{
				if (nY < pDocAnother->m_ImageOpen.GetHeight())
				{
					PixelColorAnother = pDocAnother->m_ImageOpen.GetPixel(nX, nY);
					nRAnother = GetRValue(PixelColorAnother);
					nGAnother = GetGValue(PixelColorAnother);
					nBAnother = GetBValue(PixelColorAnother);
				}
			}

			nRNew = 2 * nROne + nRAnother - 255;
			nGNew = 2 * nGOne + nGAnother - 255;
			nBNew = 2 * nBOne + nBAnother - 255;
			if (nRNew > 255)
			{
				nRNew = 255;
			}
			if (nGNew > 255)
			{
				nGNew = 255;
			}
			if (nBNew > 255)
			{
				nBNew = 255;
			}
			if (nRNew < 0) {
				nRNew = 0;
			}
			if (nGNew < 0) {
				nGNew = 0;
			}
			if (nBNew < 0) {
				nBNew = 0;
			}
			pDocNew->m_ImageOpen.SetPixel(nX, nY,
				RGB(nRNew, nGNew, nBNew));
		}
	}

	pViewNew->OnInitialUpdate();
}


void CMFCAppView::OnArithmeticScreen()
{
	// TODO: 在此添加命令处理程序代码
	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);

	CMFCAppView* pView = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDoc = pView->GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	pFrame->SendMessage(WM_COMMAND, ID_FILE_OPEN);
	CMFCAppView* pViewAnother = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocAnother = pViewAnother->GetDocument();

	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();

	pDocNew->m_ImageOpen.Create(max(pDoc->m_ImageOpen.GetWidth(), pDocAnother->m_ImageOpen.GetWidth()),
		max(pDoc->m_ImageOpen.GetHeight(), pDocAnother->m_ImageOpen.GetHeight()), 24);

	int nX; int nY;
	COLORREF PixelColorOne;
	COLORREF PixelColorAnother;
	int nROne; int nGOne; int nBOne;
	int nRAnother; int nGAnother; int nBAnother;
	int nRNew, nGNew, nBNew;

	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{
			nROne = 0; nGOne = 0; nBOne = 0;
			if (nX < pDoc->m_ImageOpen.GetWidth())
			{
				if (nY < pDoc->m_ImageOpen.GetHeight())
				{
					PixelColorOne = pDoc->m_ImageOpen.GetPixel(nX, nY);
					nROne = GetRValue(PixelColorOne);
					nGOne = GetGValue(PixelColorOne);
					nBOne = GetBValue(PixelColorOne);
				}
			}
			nRAnother = 0; nGAnother = 0; nBAnother = 0;
			if (nX < pDocAnother->m_ImageOpen.GetWidth())
			{
				if (nY < pDocAnother->m_ImageOpen.GetHeight())
				{
					PixelColorAnother = pDocAnother->m_ImageOpen.GetPixel(nX, nY);
					nRAnother = GetRValue(PixelColorAnother);
					nGAnother = GetGValue(PixelColorAnother);
					nBAnother = GetBValue(PixelColorAnother);
				}
			}
			nRNew = nROne + nRAnother - (nROne * nRAnother);
			nGNew = nGOne + nGAnother - (nGOne * nGAnother);
			nBNew = nBOne + nBAnother - (nBOne * nBAnother);

			if (nRNew > 255)
			{
				nRNew = 255;
			}
			if (nGNew > 255)
			{
				nGNew = 255;
			}
			if (nBNew > 255)
			{
				nBNew = 255;
			}
			if (nRNew < 0) {
				nRNew = 0;
			}
			if (nGNew < 0) {
				nGNew = 0;
			}
			if (nBNew < 0) {
				nBNew = 0;
			}
			pDocNew->m_ImageOpen.SetPixel(nX, nY,
				RGB(nRNew, nGNew, nBNew));
		}
	}

	pViewNew->OnInitialUpdate();
}


void CMFCAppView::OnGeometricTranslate()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;
	int nXOffset;
	int nYOffset;

	//位移量
	nXOffset = 20;
	nYOffset = -40;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();

	pDocNew->m_ImageOpen.Create(pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(), 24);

	int nX; int nY;
	COLORREF PixelColor;

	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{

			if ((nX - nXOffset) < 0)
			{
				continue;
			}

			if ((nY - nYOffset) < 0)
			{
				continue;
			}
			if ((nX - nXOffset) >= pDoc->m_ImageOpen.GetWidth())
			{
				continue;
			}

			if ((nY - nYOffset) >= pDoc->m_ImageOpen.GetHeight())
			{
				continue;
			}

			PixelColor = pDoc->m_ImageOpen.GetPixel(nX - nXOffset, nY - nYOffset);

			pDocNew->m_ImageOpen.SetPixel(nX, nY, PixelColor);

		}
	}

	pViewNew->OnInitialUpdate();
}


void CMFCAppView::OnGeometricShearhorizontal()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	float fXShear;
	fXShear = -0.5;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();

	pDocNew->m_ImageOpen.Create(pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(), 24);

	int nX;
	int nY;

	COLORREF PixelColor;

	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{
			if ((int(nX - fXShear * nY)) < 0) {
				continue;
			}
			if ((int(nX - fXShear * nY)) >= pDoc->m_ImageOpen.GetWidth()) {
				continue;
			}

			PixelColor = pDoc->m_ImageOpen.GetPixel(int(nX - fXShear * nY), int(nY));
			pDocNew->m_ImageOpen.SetPixel(nX, nY, PixelColor);
		}
	}

	pViewNew->OnInitialUpdate();
}


void CMFCAppView::OnGeometricShearvertical()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc) return;

	float fYShear;
	fYShear = float(0.5);

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();

	pDocNew->m_ImageOpen.Create(pDoc->m_ImageOpen.GetWidth(),
		int(pDoc->m_ImageOpen.GetHeight()
			+ pDoc->m_ImageOpen.GetWidth() * fYShear), 24);

	int nX; int nY;
	COLORREF PixelColor;
	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{
			if ((int(nY - fYShear * nX)) < 0)
			{
				continue;
			}
			if ((int(nY - fYShear * nX)) >= pDoc->m_ImageOpen.GetHeight())
			{
				continue;
			}
			PixelColor = pDoc->m_ImageOpen.GetPixel(nX, int(nY - fYShear * nX));
			pDocNew->m_ImageOpen.SetPixel(nX, nY, PixelColor);
		}
	}

	pViewNew->OnInitialUpdate();
}


void CMFCAppView::OnGeometricScale()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc) return;

	float Scale;
	Scale = 0.5;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();

	pDocNew->m_ImageOpen.Create(int(pDoc->m_ImageOpen.GetWidth()*Scale+0.5),
		int(pDoc->m_ImageOpen.GetHeight()*Scale+0.5), 24);

	int nX = 0;
	int nY = 0;
	COLORREF PixelColor;
	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{
		
			PixelColor = pDoc->m_ImageOpen.GetPixel(int(nX / Scale), int(nY / Scale));
			pDocNew->m_ImageOpen.SetPixel(nX, nY, PixelColor);
		}
	}
	pViewNew->OnInitialUpdate();
}


void CMFCAppView::OnGeometricScalehorizontal()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc) return;

	float Scale;
	Scale = 2;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();

	pDocNew->m_ImageOpen.Create(int(pDoc->m_ImageOpen.GetWidth() * Scale + 0.5),
		pDoc->m_ImageOpen.GetHeight(), 24);

	int nX = 0;
	int nY = 0;
	COLORREF PixelColor;
	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{

			PixelColor = pDoc->m_ImageOpen.GetPixel(int(nX / Scale), nY );
			pDocNew->m_ImageOpen.SetPixel(nX, nY, PixelColor);
		}
	}
	pViewNew->OnInitialUpdate();
}


void CMFCAppView::OnGeometricScalevertical()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc) return;

	float Scale;
	Scale = 0.5;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();

	pDocNew->m_ImageOpen.Create(pDoc->m_ImageOpen.GetWidth(),
		int(pDoc->m_ImageOpen.GetHeight() * Scale + 0.5), 24);

	int nX = 0;
	int nY = 0;
	COLORREF PixelColor;
	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{

			PixelColor = pDoc->m_ImageOpen.GetPixel(nX, int(nY / Scale));
			pDocNew->m_ImageOpen.SetPixel(nX, nY, PixelColor);
		}
	}
	pViewNew->OnInitialUpdate();
}


void CMFCAppView::OnRotateClockwise90()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc) return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew =
		(CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();

	pDocNew->m_ImageOpen.Create(pDoc->m_ImageOpen.GetHeight(),
		pDoc->m_ImageOpen.GetWidth(), 24);

	int nX; int nY;
	COLORREF PixelColor;

	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{
			PixelColor = pDoc->m_ImageOpen.GetPixel(nY, pDoc->m_ImageOpen.GetHeight() - nX - 1);
			pDocNew->m_ImageOpen.SetPixel(nX, nY, PixelColor);
		}
	}

	pViewNew->OnInitialUpdate();

}


void CMFCAppView::OnRotateClockwise180()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc) return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew =
		(CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();

	pDocNew->m_ImageOpen.Create(pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(), 24);

	int nX; int nY;
	COLORREF PixelColor;

	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{
			PixelColor = pDoc->m_ImageOpen.GetPixel(pDoc->m_ImageOpen.GetWidth() - nX - 1,
				pDoc->m_ImageOpen.GetHeight() - nY - 1);
			pDocNew->m_ImageOpen.SetPixel(nX, nY, PixelColor);

		}
	}

	pViewNew->OnInitialUpdate();
}


void CMFCAppView::OnRotateClockwise270()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc) return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew =
		(CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();

	pDocNew->m_ImageOpen.Create(pDoc->m_ImageOpen.GetHeight(),
		pDoc->m_ImageOpen.GetWidth(), 24);

	int nX; int nY;
	COLORREF PixelColor;

	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{
			PixelColor = pDoc->m_ImageOpen.GetPixel(pDoc->m_ImageOpen.GetWidth() - nY - 1,nX);
			pDocNew->m_ImageOpen.SetPixel(nX, nY, PixelColor);

		}
	}

	pViewNew->OnInitialUpdate();
}


void CMFCAppView::OnRotateArbitrary()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc) return;

	float fAngle;
	fAngle = 45;

	float fArc;
	fArc = -float(fAngle * 3.1415927 / 180);

	double fSin;
	fSin = sin(fArc);

	double fCos;
	fCos = cos(fArc);

	int nXLeftTop;
	nXLeftTop = -(pDoc->m_ImageOpen.GetWidth() - 1) / 2;

	int nYLeftTop;
	nYLeftTop = (pDoc->m_ImageOpen.GetHeight() - 1) / 2;

	int nXRightTop;
	nXRightTop = (pDoc->m_ImageOpen.GetWidth() - 1) / 2;

	int nYRightTop;
	nYRightTop = (pDoc->m_ImageOpen.GetHeight() - 1) / 2;

	int nXRightBottom;
	nXRightBottom = (pDoc->m_ImageOpen.GetWidth() - 1) / 2;

	int nYRightBottom;
	nYRightBottom = -(pDoc->m_ImageOpen.GetHeight() - 1) / 2;

	int nXLeftBottom;
	nXLeftBottom = -(pDoc->m_ImageOpen.GetWidth() - 1) / 2;

	int nYLeftBottom;
	nYLeftBottom = -(pDoc->m_ImageOpen.GetHeight() - 1) / 2;

	int nXLeftTopRotated;
	nXLeftTopRotated = int(nXLeftTop * fCos + nYLeftTop * fSin); //

	int nYLeftTopRotated;
	nYLeftTopRotated = int(-nXLeftTop * fSin + nYLeftTop * fCos);

	int nXRightTopRotated;
	nXRightTopRotated = int(nXRightTop * fCos + nYRightTop * fSin);

	int nYRightTopRotated;
	nYRightTopRotated = int(-nXRightTop * fSin + nYRightTop * fCos);

	int nXRightBottomRotated;
	nXRightBottomRotated = int(nXRightBottom * fCos + nYRightBottom * fSin);

	int nYRightBottomRotated;
	nYRightBottomRotated = int(-nXRightBottom * fSin + nYRightBottom * fCos);

	int nXLeftBottomRotated;
	nXLeftBottomRotated = int(nXLeftBottom * fCos + nYLeftBottom * fSin);

	int nYLeftBottomRotated;
	nYLeftBottomRotated = int(-nXLeftBottom * fSin + nYLeftBottom * fCos);

	int nWidthRotated;
	nWidthRotated = int(max(abs(nXRightBottomRotated - nXLeftTopRotated),
		abs(nXLeftBottomRotated - nXRightTopRotated)) + 0.5);

	int nHeightRotated;
	nHeightRotated = int(max(abs(nYRightBottomRotated - nYLeftTopRotated),
		abs(nYLeftBottomRotated - nYRightTopRotated)) + 0.5);

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();
	pDocNew->m_ImageOpen.Create(nWidthRotated, nHeightRotated, 24);

	int nWidthRotatedAdd;
	nWidthRotatedAdd = int(-(nWidthRotated - 1) * 0.5 * fCos
		+ (nHeightRotated - 1) * 0.5 * fSin
		+ (pDoc->m_ImageOpen.GetWidth() - 1) * 0.5);

	int nHeightRotatedAdd;
	nHeightRotatedAdd = int(-(nWidthRotated - 1) * 0.5 * fSin
		- (nHeightRotated - 1) * 0.5 * fCos
		+ (pDoc->m_ImageOpen.GetHeight() - 1) * 0.5);

	int nX; int nY;
	COLORREF PixelColor;
	int nXOriginal;
	int nYOriginal;

	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{
			nXOriginal = int(nX * fCos - nY * fSin + nWidthRotatedAdd + 0.5);
			nYOriginal = int(nX * fSin + nY * fCos + nHeightRotatedAdd + 0.5);
			if (nXOriginal < 0)
			{
				continue;
			}
			if (nYOriginal < 0)
			{
				continue;
			}
			if (nXOriginal >= pDoc->m_ImageOpen.GetWidth())
			{
				continue;
			}
			if (nYOriginal >= pDoc->m_ImageOpen.GetHeight())
			{
				continue;
			}
			PixelColor = pDoc->m_ImageOpen.GetPixel(nXOriginal, nYOriginal);
			pDocNew->m_ImageOpen.SetPixel(nX, nY, PixelColor);
		}
	}

	pViewNew->OnInitialUpdate();
}


void CMFCAppView::OnMirrorHorizontal()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc) return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewHorizontal = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocHorizontal = pViewHorizontal->GetDocument();
	pDocHorizontal->m_ImageOpen.Create(pDoc->m_ImageOpen.GetWidth(), pDoc->m_ImageOpen.GetHeight(), 24);
	
	int nX; int nY;
	COLORREF PixelColor;
	for (nY = 0; nY < pDocHorizontal->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocHorizontal->m_ImageOpen.GetWidth(); nX++)
		{
			PixelColor = pDoc->m_ImageOpen.GetPixel(nX, nY);
			pDocHorizontal->m_ImageOpen.SetPixel(pDocHorizontal->m_ImageOpen.GetWidth() - 1 - nX, nY, PixelColor);
		}
	}
	pViewHorizontal->OnInitialUpdate();
}


void CMFCAppView::OnMirrorVertical()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc) return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewVertical = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocVertical = pViewVertical->GetDocument();
	pDocVertical->m_ImageOpen.Create(pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(), 24);

	int nX; int nY;
	COLORREF PixelColor;

	for (nY = 0; nY < pDocVertical->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocVertical->m_ImageOpen.GetWidth(); nX++)
		{
			PixelColor = pDoc->m_ImageOpen.GetPixel(nX, nY);
			pDocVertical->m_ImageOpen.SetPixel(nX, pDocVertical->m_ImageOpen.GetHeight() - 1 - nY, PixelColor);
		}
	}

	pViewVertical->OnInitialUpdate();
}


void CMFCAppView::OnMirrorBoth()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc) return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewHorizontalVertical = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocHorizontalVertical = pViewHorizontalVertical->GetDocument();

	pDocHorizontalVertical->m_ImageOpen.Create(pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(), 24);

	int nX; int nY;
	COLORREF PixelColor;

	for (nY = 0; nY < pDocHorizontalVertical->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocHorizontalVertical->m_ImageOpen.GetWidth(); nX++)
		{
			PixelColor = pDoc->m_ImageOpen.GetPixel(nX, nY);
			pDocHorizontalVertical->m_ImageOpen.SetPixel(
				pDocHorizontalVertical->m_ImageOpen.GetWidth() - 1 - nX,
				pDocHorizontalVertical->m_ImageOpen.GetHeight() - 1 - nY, PixelColor);
		}
	}

	pViewHorizontalVertical->OnInitialUpdate();

}


void CMFCAppView::OnGeometricSpherical()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc) return;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew = (CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();
	pDocNew->m_ImageOpen.Create(pDoc->m_ImageOpen.GetWidth(),pDoc->m_ImageOpen.GetHeight(), 24);

	int nX; int nY;
	COLORREF PixelColor;
	int nXOriginal;
	int nYOriginal;

	int nDx;
	int nDy;

	int nXc;
	int nYc;

	nXc = pDoc->m_ImageOpen.GetWidth() / 2;
	nYc = pDoc->m_ImageOpen.GetHeight() / 2;
	int nR;

	int nRMax;

	nRMax = pDoc->m_ImageOpen.GetWidth() / 2;

	double dRo;
	dRo = 1.8;
	float fBetaX;
	float fBetaY;

	double dZ;

	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{
			nDx = nX - nXc;
			nDy = nY - nYc;
			nR = sqrt(float(nDx * nDx + nDy * nDy));
			dZ = sqrt(float(nRMax * nRMax - nR * nR));

			fBetaX = (1 - 1 / dRo) * asin(nDx * 1.0 / sqrt(float(nDx * nDx + dZ * dZ)));
			fBetaY = (1 - 1 / dRo) * asin(nDy * 1.0 / sqrt(float(nDy * nDy + dZ * dZ)));

			if (nR <= nRMax)
			{
				nXOriginal = int(nX - dZ * tan(fBetaX));
			}
			else
			{
				nXOriginal = nX;
			}
			if (nR <= nRMax)
			{
				nYOriginal = int(nY - dZ * tan(fBetaY));
			}
			else
			{
				nYOriginal = nY;
			}
			if (nYOriginal < 0)
			{
				continue;
			}
			if ((nXOriginal) < 0)
			{
				continue;
			}
			if (nXOriginal >= pDoc->m_ImageOpen.GetWidth())
			{
				continue;
			}
			if (nYOriginal >= pDoc->m_ImageOpen.GetHeight())
			{
				continue;
			}
			PixelColor = pDoc->m_ImageOpen.GetPixel(nXOriginal, nYOriginal);
			pDocNew->m_ImageOpen.SetPixel(nX, nY, PixelColor);
		}
	}

	pViewNew->OnInitialUpdate();

}


void CMFCAppView::OnGeometricRipple()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc) return;

	int nAX = 32;
	int nAY = 16;
	int nTX = 4;
	int nTY = 2;

	double dAx;
	dAx = pDoc->m_ImageOpen.GetWidth() / nAX;
	double dAy;
	dAy = pDoc->m_ImageOpen.GetHeight() / nAY;
	double dTx;
	dTx = pDoc->m_ImageOpen.GetWidth() / nTX;
	double dTy;
	dTy = pDoc->m_ImageOpen.GetHeight() / nTY;

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew =(CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();
	pDocNew->m_ImageOpen.Create(pDoc->m_ImageOpen.GetWidth(),pDoc->m_ImageOpen.GetHeight(), 24);

	int nX; int nY;
	COLORREF PixelColor;
	int nXOriginal;
	int nYOriginal;
	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{
			nXOriginal = nX + dAx * sin(2 * 3.1415927 * nY / dTx);
			nYOriginal = nY + dAy * sin(2 * 3.1415927 * nX / dTy);

			if (nXOriginal >= pDoc->m_ImageOpen.GetWidth() || nXOriginal<0) {
				continue;
			}
			if (nYOriginal >= pDoc->m_ImageOpen.GetHeight() || nYOriginal < 0) {
				continue;
			}

			PixelColor = pDoc->m_ImageOpen.GetPixel(nXOriginal, nYOriginal);
			pDocNew->m_ImageOpen.SetPixel(nX, nY, PixelColor);
		}
	}

	pViewNew->OnInitialUpdate();

}


void CMFCAppView::OnGeometricTwirl()
{
	// TODO: 在此添加命令处理程序代码
	CMFCAppDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc) return;

	float fAngle;
	fAngle = 45;

	float fArc;
	fArc = float(fAngle * 3.1415927 / 180);

	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
	CMFCAppView* pViewNew =
		(CMFCAppView*)pFrame->MDIGetActive()->GetActiveView();
	CMFCAppDoc* pDocNew = pViewNew->GetDocument();
	pDocNew->m_ImageOpen.Create(pDoc->m_ImageOpen.GetWidth(),
		pDoc->m_ImageOpen.GetHeight(), 24);

	int nX; int nY;
	COLORREF PixelColor;
	int nXOriginal;
	int nYOriginal;

	int nDx;
	int nDy;

	int nXc;
	int nYc;

	nXc = pDoc->m_ImageOpen.GetWidth() / 2;
	nYc = pDoc->m_ImageOpen.GetHeight() / 2;

	int nR;

	int nRMax;

	nRMax = sqrt(float(pDoc->m_ImageOpen.GetWidth() * pDoc->m_ImageOpen.GetWidth()
		+ pDoc->m_ImageOpen.GetHeight() * pDoc->m_ImageOpen.GetHeight())) / 2;

	float fBeta;

	for (nY = 0; nY < pDocNew->m_ImageOpen.GetHeight(); nY++)
	{
		for (nX = 0; nX < pDocNew->m_ImageOpen.GetWidth(); nX++)
		{
			nDx = nX - nXc;
			nDy = nY - nYc;
			nR = sqrt(float(nDx * nDx + nDy * nDy));
			fBeta = atan2(nDy, nDx * 1.0) + fArc * (nRMax - nR) / nRMax;
			if (nR <= nRMax)
			{
				nXOriginal = int(nXc + nR * cos(fBeta));
			}
			else
			{
				nXOriginal = nX;
			}

			if (nR <= nRMax)
			{
				nYOriginal = int(nYc + nR * sin(fBeta));
			}
			else
			{
				nYOriginal = nY;
			}
			if (nYOriginal < 0)
			{
				continue;
			}
			if ((nXOriginal) < 0)
			{
				continue;
			}

			if (nXOriginal >= pDoc->m_ImageOpen.GetWidth())
			{
				continue;
			}

			if (nYOriginal >= pDoc->m_ImageOpen.GetHeight())
			{
				continue;
			}
			PixelColor = pDoc->m_ImageOpen.GetPixel(nXOriginal, nYOriginal);
			pDocNew->m_ImageOpen.SetPixel(nX, nY, PixelColor);
		}
	}
	pViewNew->OnInitialUpdate();

}
